import cf from "../../../utils/config2"
// import Request from "../../../utils/request.js";
import CHARTS from '../../../lib/js/wxcharts-min.js';
// import Big from '../../../lib/js/big.min.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:'',
    receptionUrl:'zmzj/data/queryReceptionDataByPhone',
    subscriptionUrl:'zmzj/data/querySubscriptionDataByPhone',
    listData:[],
    query:{
      currPage:1,
      pageSize:10,
      totalCount:0,
      totalPage:0
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      type:options.type
    })
   this.getList();
  },
  //获取列表数据
  getList(){
    let token = wx.getStorageSync('authName');   
    var _this = this
    let {receptionUrl,subscriptionUrl,type,query,listData}=this.data
    let requestUrl = type==1?receptionUrl:subscriptionUrl
    // let phoneNo = type==1?17776681436:17304084411
    let phoneNo = wx.getStorageSync('phoneNo');   

    wx.showLoading({
      title:'正在获取...'
    });
    wx.request({
      url:cf.dataCenter+ requestUrl+`/${phoneNo}/${query.currPage}/${query.pageSize}`,
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {token}, // 设置请求的 header
      success: function(res){
        wx.hideLoading();
        // success
        let {data} = res.data
        query.totalCount = data.totalCount
        query.totalPage = data.totalPage
        query.currPage = data.currPage
        listData = [...listData,...data.list]
        _this.setData({
          listData,
          query
        })
        
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
 //拨打电话
 tel(e){
  // console.log(e.currentTarget.dataset.tel)
  let {tel}=e.currentTarget.dataset
  wx.makePhoneCall({
    phoneNumber: tel
  })
 },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var _this=this
    let {query,listData} = _this.data
    
    if(query.totalCount > listData.length){
      query.currPage++
      _this.setData({
        query
      })
      _this.getList();
    }else{
      // wx.showToast({
      //   title:'暂无更多数据'
      // })
    }
   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})